package com.ff.neuropp.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ff.neuropp.domain.Course;
import com.ff.neuropp.domain.CourseDate;
import com.ff.neuropp.domain.Order;
import com.ff.neuropp.repository.CourseRepository;
import com.ff.neuropp.repository.OrderRepository;
import com.ff.neuropp.response.ScheduleReponse;
import com.ff.neuropp.util.ResultTool;

@Service
public class MyScheduleService {

	@Resource
	private OrderRepository orderRepository;

	@Resource
	private CourseRepository courseRepository;

	/**
	 * 我的日程 查询订单表购买的课程
	 * 
	 * @param userId
	 * @return
	 */
	public Map<String, Object> scheduleInfo(String userId) {
		//根据当前用户ID查询出订单下购买了哪些课程作为日程表
		List<Order> schedules = orderRepository.findAllByUserIdAndOrderStatus(userId, 1);
		List<ScheduleReponse> reponsesList = new ArrayList<ScheduleReponse>();
		if (schedules.size() > 0) {
			for (Order order : schedules) {
				ScheduleReponse reponse = new ScheduleReponse();
				Course course = order.getCourse();
				reponse.setCourseId(course.getId());
				reponse.setCourseName(course.getCourseName());
				//reponse.setCourseTime(course.getCourseName());
				reponse.setCourseLocation(course.getCourseLocation());
				if(course.getCourseDateList().size()>0) {
					for(CourseDate courseDate:course.getCourseDateList()) {
						courseDate.setCourseTime(courseDate.getCourseStartTime());
					}
				}
				reponse.setCourseDateList(course.getCourseDateList());
				reponsesList.add(reponse);
			}

		}
		return ResultTool.genSuccessResult(reponsesList);
	}

}
